<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="../../include/tag.jsp" %>
<!DOCTYPE html>
<html lang="zh">
<head>
    <title>字典管理</title>
    <link rel="stylesheet" href="${ctx}/css/common/list.css">
    <link rel="stylesheet" href="${ctx}/css/common/table.css">
    <%@include file="../../include/commonFile.jsp" %>
</head>
<body>
<!--头部-->
<%@include file="../../include/header.jsp" %>
<div class="index-outside">
    <%@include file="../../include/sidebar.jsp" %>
    <!--内容-->
    <section>
        <div class="section-main">
            <form class="layui-form" action="${ctx}/system/dict/dictList.do?type=${dict.type}" id="myForm"
                  method="post">
                <div class="f-search-bar">
                    <div class="search-container">
                        <ul class="search-form-content">
                            <li class="form-item-inline"><label class="search-form-lable">标签</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="label" autocomplete="off" class="layui-input"
                                           value="${dict.label}" placeholder="标签">
                                </div>
                            </li>
                            <li class="form-item-inline">
                                <div class="sub-btns">
                                    <a class="layui-btn layui-btn-danger"
                                       href="javascript:submitFunction('#myForm')">查询</a>
                                    <a class="layui-btn layui-btn-normal"
                                       href="javascript:resetFunction('#myForm')">重置</a>
                                </div>
                            </li>
                        </ul>
                    </div>
                </div>
            </form>
            <div class="list-content">
                <div class="cl">
                    <table class="layui-table">
                        <colgroup>
                            <col>
                            <col>
                            <col>
                            <col>
                            <col>
                            <col>
                            <col>
                            <col>
                        </colgroup>
                        <thead>
                        <tr>
                            <th>字典标签</th>
                            <th>字典键值</th>
                            <th>字典类型</th>
                            <th>字典描述</th>
                            <th>排序号</th>
                            <th>更新时间</th>
                            <th>状态</th>
                            <th>操作</th>
                        </tr>
                        </thead>
                        <tbody>
                        <c:forEach var="systemDict" items="${dicts}">
                            <tr>
                                <td>
                                        ${systemDict.label}
                                </td>
                                <td>
                                        ${systemDict.value}
                                </td>
                                <td>
                                        ${systemDict.type}
                                </td>
                                <td>
                                        ${systemDict.description}
                                </td>
                                <td>
                                        ${systemDict.sort}
                                </td>
                                <td>
                                    <fmt:formatDate value="${systemDict.updateDate}" pattern="yyyy-MM-dd HH:mm"/>
                                </td>
                                <td>
                                        ${systemDict.openStatus == 1 ? '启用' : '不启用'}
                                </td>
                                <td class="tb-opts">
                                    <div class="comm-opts">
                                        <a href="${ctx}/system/dict/view.do?id=${systemDict.id}&type=${dict.type}"
                                           target="_self">
                                            编辑
                                        </a>
                                        <a href="javascript:deleteLogicDict('${systemDict.id}');">
                                            删除
                                        </a>
                                        <c:if test="${systemDict.openStatus == 1}">
                                            <a href="javascript:changeOpenStatus('${systemDict.id}', 0)">不启用</a>
                                        </c:if>
                                        <c:if test="${systemDict.openStatus == 0}">
                                            <a href="javascript:changeOpenStatus('${systemDict.id}', 1)">启用</a>
                                        </c:if>
                                    </div>
                                </td>
                            </tr>
                        </c:forEach>
                        </tbody>
                    </table>
                </div>
            </div>
        </div><!--底部-->
        <%@include file="../../include/footer.jsp" %>
    </section>
</div>


<script type="text/javascript" src="${ctx}/script/common/list.js"></script>
<script type="text/javascript" src="${ctx}/script/common/table_option.js"></script>
<script type="text/javascript">
    txz.initHeader({
        nav: [{
            name: '字典管理',
            href: '${ctx}/system/dict/typeList.do'
        }, {
            name: '${dict.type}',
            curr: true
        }],
        btns: [{
            name: '返回',
            href: '${ctx}/system/dict/typeList.do',
            icon: 'back'
        }, {
            name: '添加字典数据',
            href: '${ctx}/system/dict/view.do?type=${dict.type}',
            icon: 'add'
        }]
    });

    function changeOpenStatus(id, openStatus) {
        layer.confirm('确定要操作？', {
            icon: 3,
            title: '系统提示'
        }, function (index) {
            $.post("${ctx}/system/dict/updateStatus.do", {id: id, openStatus: openStatus}, function (res) {
                if (res.success) {
                    util.layerMsgSuccess("操作成功", function () {
                        window.location.reload();
                    })
                } else {
                    util.layerMsgError("操作失败")
                }
            })
        });
    }

    function deleteLogicDict(id) {
        layer.confirm('确定删除？', {
            icon: 3,
            title: '系统提示'
        }, function (index) {
            $.post("${ctx}/system/dict/delete.do", {
                id: id
            }, function (data) {
                if (data.success == true) {
                    util.layerMsgSuccess("删除成功", function () {
                        window.location.reload();
                    })
                } else {
                    util.layerMsgError("删除失败")
                }
            });
        });
    }
</script>
</body>
</html>